<?php
require("../dbhead.php");


$data = array('name', 'affiliation', 'userid', 'password', 'category', 'grade');

foreach ($data as $key) {
	if (array_key_exists($key, $_POST) && $_POST[$key] != '') {
		$$key = $_POST[$key];
	} else {
		header("Location: signup_form.php");	// 에러 메시지를 GET으로 넘기기!
	}
}

// Check variables

if ($name == "" or $affiliation == "" or $userid == "" or $password == "" or $category == "" or $grade == "")
	echo "Back!"; // Error

// Insert user data

$query = "INSERT INTO user (userid, password, name, affiliation, category, grade) values ('${userid}', PASSWORD('${password}'), '${name}', '${affiliation}', '${category}', '${grade}')";
$row = mysql_query($query) or dberr($connect, $query, __LINE__);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>EMRS sign up page</title>
		<link rel="stylesheet" type="text/css" href="../css/default.css" />
	</head>
	<body>
		<div>등록되었습니다.</div>
		<div><a href="../">Home</a></div>
	</body>
</html>